package com.train.mgr.config.thread;


import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public final class AsyncExecutors {

    /** IO 密集型：网络、磁盘、ffmpeg */
    public static final Executor IO =
            new ThreadPoolExecutor(16, 100, 60L, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<>(200),
                    new ThreadFactoryBuilder().setNameFormat("io-%d").build(),
                    new ThreadPoolExecutor.CallerRunsPolicy());

    /** CPU 密集型：评分算法 */
    public static final Executor CPU =
            new ThreadPoolExecutor(8, 40, 60L, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<>(100),
                    new ThreadFactoryBuilder().setNameFormat("cpu-%d").build(),
                    new ThreadPoolExecutor.CallerRunsPolicy());

    private AsyncExecutors() {}
}